
* Malaria and Conflict
* This script replicates vaccine counterfactual



********************************************************************************
*                                Preliminaries                                 *
********************************************************************************

clear all

set matsize 11000

* Set path:
* global dir "PATH"
* cd "$dir"





********************************************************************************
*                            Vaccine Counterfactual                            *
********************************************************************************

use "conflict_monthly.dta", clear


* Generate predicted values

areg acled_conflict_dv mal_suit_month mal_suit_month_x_epidem_area mean_prec ///
    mean_temp spei mean_prec_lag* mean_temp_lag* spei_lag* MONTHdum* ///
    if sample==1, absorb(cellyear) cluster(cell_id)

predict conflict_predicted, xb

keep if sample==1


* Multiply beta with observed value

gen msm_x_epidem_area_beta = ///
    mal_suit_month_x_epidem_area*_b[mal_suit_month_x_epidem_area]


* Substract from predicted value

gen vaccine_prediction = conflict_predicted - msm_x_epidem_area_beta 


* Set negative values to 0

replace conflict_predicted = 0 if conflict_predicted < 0
replace vaccine_prediction = 0 if vaccine_prediction < 0


* Take means for each cell

egen conflict_predicted_mean = mean(conflict_predicted), by(cell_id)
egen vaccine_prediction_mean = mean(vaccine_prediction), by(cell_id)


* Compute percentage change

gen vaccine_change_percent = ///
    (conflict_predicted_mean - vaccine_prediction_mean ) ///
    / conflict_predicted_mean


* Save data

keep cell_id vaccine_change_percent

duplicates drop

 


********************************************************************************
*                        Climate Change Counterfactual                         *
********************************************************************************

use "conflict_monthly.dta", clear


*** Generate Predicted Values for Observed Data

areg acled_conflict_dv mal_suit_month mal_suit_month_x_epidem_area mean_prec ///
    mean_temp spei mean_prec_lag* mean_temp_lag* spei_lag* MONTHdum* ///
    if sample==1, absorb(cellyear) cluster(cell_id)

predict conflict_predicted, xb

replace conflict_predicted = 0 if conflict_predicted < 0


* Compute cell means

bysort cell_id: egen pred_mean_0 = mean(conflict_predicted)


*** Generate Predicted Values for Projected Climate Data

* Define Macros for models

local model_short cesm_cam5 csiro_mk360 fio_esm gfdl_esm2g giss_e2_r ///
    ipsl_cm5a_lr miroc_esm_chem mohc_hadgem2_es mri_cgcm3 ncar_ccsm4 ///
    ncc_noresm1_m

local rcps "26 45 60 85"

local model_list " "

foreach my_model of local model_short{
	foreach rcp of local rcps{
		local model_long "`my_model'_`rcp'"
		local model_list "`model_list' `model_long'"
	}	
}


* Generate Interaction Terms

foreach model of local model_list{
	gen msm_`model'_int = msm_`model' * epidem_area
}
	

* Multiply Controls and Parameters

gen controls = 0

foreach var of varlist mean_prec mean_temp spei mean_prec_lag* ///
    mean_temp_lag* spei_lag* MONTHdum*{
	
    gen `var'_beta = _b[`var'] * `var'
	/// local controls "`controls'" " " "`var'_beta"
	replace controls = controls + `var'_beta
}

di "`controls'"


* Generate Predicted Values for all models

foreach model of local model_list{
	gen msm_`model'_pred = _b[_cons] * _cons ///
    + _b[mal_suit_month] * msm_`model' ///
    + _b[mal_suit_month_x_epidem_area] * msm_`model'_int + controls
	replace msm_`model'_pred = 0 if msm_`model'_pred < 0	
	bysort cell_id : egen msm_`model'_mean = mean(msm_`model'_pred)
}


* Generate Means for Different Scenarios

foreach rcp of local rcps{
	egen pred_mean_`rcp' = rowmean(msm_*_`rcp'_mean)
}


* Generate Mean of All Scenarios

egen pred_mean_all = rowmean(pred_mean_26 pred_mean_45 pred_mean_60 ///
    pred_mean_85)


* Compute Difference Between Baseline and Mean Projected Prediction

gen pred_mean_0_all = pred_mean_all - pred_mean_0


* Save file

keep cell_id  pred_mean_0_all

label var pred_mean_0_all "Pred. Perc. Change of Years w. Conflict Events Due to Climate Change (Mean of All Models)"

duplicates drop

 












